#include "header/pyramid_entrance.h"

OSG_USING_NAMESPACE

double pyraEn_height = 2500;
double pyraEn_width = 2500;
double pyraEn_door_height = 90;
double pyraEn_door_width = 70;
double pyraEn_door_height_begin = 100;
double entrance_length = 600;

NodePtr createEntrance()
{
	Matrix m;	
	float winkel = tan(M_PI/2-atan(pyraEn_height/(pyraEn_width/2)));

	ImagePtr image = Image::create();
	image->read("materials/cryptWall.jpg");
	
    
    
	
	
#ifdef ENTRANCE_PLANES_ON
	// *********** Left Entrance Pass ***********
	NodePtr leftPass = makePlane(entrance_length-winkel*pyraEn_door_height, pyraEn_door_height, 10, 10);
	setName(leftPass, "entranceLeftPass");
	
	TransformPtr tleftPass = Transform::create();
	beginEditCP(tleftPass, Transform::MatrixFieldMask);
		m.setIdentity();
		m.setTranslate(0, pyraEn_door_height/2, (entrance_length-winkel*pyraEn_door_height)/2);
		m.setRotate(Quaternion(Vec3f(0,1,0), M_PI/2));
		tleftPass->setMatrix(m);
	endEditCP(tleftPass, Transform::MatrixFieldMask);
	    
	NodePtr leftPassTrans = Node::create();
	beginEditCP(leftPassTrans, Node::CoreFieldMask | Node::ChildrenFieldMask);
		leftPassTrans->setCore(tleftPass);
		leftPassTrans->addChild(leftPass);
	endEditCP(leftPassTrans, Node::CoreFieldMask | Node::ChildrenFieldMask);
	
	
	// *********** Right Entrance Pass ***********
	NodePtr rightPass = makePlane(entrance_length-winkel*pyraEn_door_height, pyraEn_door_height, 10, 10);
	setName(rightPass, "entranceRightPass");
	
	TransformPtr trightPass = Transform::create();
	beginEditCP(trightPass, Transform::MatrixFieldMask);
		m.setIdentity();
		m.setTranslate(pyraEn_door_width, pyraEn_door_height/2, (entrance_length-winkel*pyraEn_door_height)/2);
		m.setRotate(Quaternion(Vec3f(0,1,0), M_PI/2+M_PI));
		trightPass->setMatrix(m);
	endEditCP(trightPass, Transform::MatrixFieldMask);
	    
	NodePtr rightPassTrans = Node::create();
	beginEditCP(rightPassTrans, Node::CoreFieldMask | Node::ChildrenFieldMask);
		rightPassTrans->setCore(trightPass);
		rightPassTrans->addChild(rightPass);
	endEditCP(rightPassTrans, Node::CoreFieldMask | Node::ChildrenFieldMask);



	// *********** Left Entrance ***********
	// Tuer
	// links oben
	float left_v0[3] = {0, pyraEn_door_height, entrance_length-winkel*pyraEn_door_height};
	// links unten
	float left_v1[3] = {0, 0, entrance_length};
	
	// Gang
	// links oben
	float left_v2[3] = {0, pyraEn_door_height, entrance_length-winkel*pyraEn_door_height-1};
	// links unten
	float left_v3[3] = {0, 0, entrance_length-winkel*pyraEn_door_height-1};
	
	// Definieren der benoetigten Typen
	GeoPTypesPtr leftType = GeoPTypesUI8::create();
	beginEditCP (leftType, GeoPTypesUI8::GeoPropDataFieldMask);
	{
		leftType->addValue(GL_QUADS);
	}
	endEditCP (leftType, GeoPTypesUI8::GeoPropDataFieldMask);
	
	// Anzahl der Punkte die fuer die einzelnen Typen benoetigt werden
	GeoPLengthsPtr leftLens = GeoPLengthsUI32::create();    
	beginEditCP (leftLens, GeoPLengthsUI32::GeoPropDataFieldMask);
	{
		leftLens->addValue(4);
	}
	endEditCP (leftLens, GeoPLengthsUI32::GeoPropDataFieldMask);
	
	// Setzen der Punkte
	GeoPositions3fPtr leftPnts = GeoPositions3f::create();
	beginEditCP (leftPnts, GeoPositions3f::GeoPropDataFieldMask);
	{		
		leftPnts->addValue(Pnt3f(left_v0[0], left_v0[1], left_v0[2]));
		leftPnts->addValue(Pnt3f(left_v1[0], left_v1[1], left_v1[2]));
		leftPnts->addValue(Pnt3f(left_v2[0], left_v2[1], left_v2[2]));
		leftPnts->addValue(Pnt3f(left_v3[0], left_v3[1], left_v3[2]));
	}
	endEditCP (leftPnts, GeoPositions3f::GeoPropDataFieldMask);

	// Zusammenfuegen der Punkte in die oben angegebenen Formen
	GeoIndicesUI32Ptr leftIndices = GeoIndicesUI32::create();
	beginEditCP (leftIndices, GeoIndicesUI32::GeoPropDataFieldMask);
	{	
		// links
		leftIndices->addValue(1);
		leftIndices->addValue(0);
		leftIndices->addValue(2);
		leftIndices->addValue(3);
	}
	endEditCP (leftIndices, GeoIndicesUI32::GeoPropDataFieldMask);

	
	GeoTexCoords2fPtr leftTex = GeoTexCoords2f::create();
	beginEditCP (leftTex);
	{
		leftTex->addValue(Vec2f(left_v0[1]/pyraEn_door_height, left_v0[2]/entrance_length));
		leftTex->addValue(Vec2f(left_v1[1]/pyraEn_door_height, left_v1[2]/entrance_length));

		leftTex->addValue(Vec2f(left_v2[1]/pyraEn_door_height, left_v2[2]/entrance_length));
		leftTex->addValue(Vec2f(left_v3[1]/pyraEn_door_height, left_v3[2]/entrance_length));
	}
	endEditCP (leftTex);
	
	GeoNormals3fPtr leftNorms = GeoNormals3f::create();
	beginEditCP(leftNorms, GeoNormals3f::GeoPropDataFieldMask);
	{
		for (int x = 0; x < 4; x++)
			leftNorms->addValue(Vec3f(1,0,0));
	}
	endEditCP (leftNorms, GeoNormals3f::GeoPropDataFieldMask);
	

	
	// Zusammenfuegen der Eigenschaften
	GeometryPtr leftgeo=Geometry::create();
	beginEditCP (leftgeo, Geometry::TypesFieldMask    |
			Geometry::LengthsFieldMask   |
			Geometry::IndicesFieldMask   |
			Geometry::PositionsFieldMask |
			Geometry::MaterialFieldMask  );
	{
		leftgeo->setTypes    (leftType);
		leftgeo->setLengths  (leftLens);
		leftgeo->setIndices  (leftIndices);
		leftgeo->setTexCoords(leftTex);
		leftgeo->setPositions(leftPnts);
		leftgeo->setNormals  (leftNorms);
	}
	endEditCP (leftgeo, Geometry::TypesFieldMask    |
			Geometry::LengthsFieldMask   |
			Geometry::IndicesFieldMask   |
			Geometry::PositionsFieldMask |
			Geometry::MaterialFieldMask  );

	// Erstellen eines Knotens
	NodePtr leftNode = Node::create();
	beginEditCP(leftNode, Node::CoreFieldMask);
	{
		leftNode->setCore(leftgeo);
	}
	endEditCP  (leftNode, Node::CoreFieldMask);
	
	
	
	
	// *********** Right Entrance ***********
	// Tuer
	// links oben
	float right_v0[3] = {pyraEn_door_width, pyraEn_door_height, entrance_length-winkel*pyraEn_door_height};
	// links unten
	float right_v1[3] = {pyraEn_door_width, 0, entrance_length};
	
	// Gang
	// links oben
	float right_v2[3] = {pyraEn_door_width, pyraEn_door_height, entrance_length-winkel*pyraEn_door_height-1};
	// links unten
	float right_v3[3] = {pyraEn_door_width, 0, entrance_length-winkel*pyraEn_door_height-1};
	
	// Definieren der benoetigten Typen
	GeoPTypesPtr rightType = GeoPTypesUI8::create();
	beginEditCP (rightType, GeoPTypesUI8::GeoPropDataFieldMask);
	{
		rightType->addValue(GL_QUADS);
	}
	endEditCP (rightType, GeoPTypesUI8::GeoPropDataFieldMask);
	
	// Anzahl der Punkte die fuer die einzelnen Typen benoetigt werden
	GeoPLengthsPtr rightLens = GeoPLengthsUI32::create();    
	beginEditCP (rightLens, GeoPLengthsUI32::GeoPropDataFieldMask);
	{
		rightLens->addValue(4);
	}
	endEditCP (rightLens, GeoPLengthsUI32::GeoPropDataFieldMask);
	
	// Setzen der Punkte
	GeoPositions3fPtr rightPnts = GeoPositions3f::create();
	beginEditCP (rightPnts, GeoPositions3f::GeoPropDataFieldMask);
	{		
		rightPnts->addValue(Pnt3f(right_v0[0], right_v0[1], right_v0[2]));
		rightPnts->addValue(Pnt3f(right_v1[0], right_v1[1], right_v1[2]));
		rightPnts->addValue(Pnt3f(right_v2[0], right_v2[1], right_v2[2]));
		rightPnts->addValue(Pnt3f(right_v3[0], right_v3[1], right_v3[2]));
	}
	endEditCP (rightPnts, GeoPositions3f::GeoPropDataFieldMask);

	// Zusammenfuegen der Punkte in die oben angegebenen Formen
	GeoIndicesUI32Ptr rightIndices = GeoIndicesUI32::create();
	beginEditCP (rightIndices, GeoIndicesUI32::GeoPropDataFieldMask);
	{	
		// links
		rightIndices->addValue(1);
		rightIndices->addValue(0);
		rightIndices->addValue(2);
		rightIndices->addValue(3);
	}
	endEditCP (rightIndices, GeoIndicesUI32::GeoPropDataFieldMask);
	
	GeoTexCoords2fPtr rightTex = GeoTexCoords2f::create();
	beginEditCP (rightTex);
	{
		rightTex->addValue(Vec2f(right_v0[1]/pyraEn_door_height, right_v0[2]/entrance_length));
		rightTex->addValue(Vec2f(right_v1[1]/pyraEn_door_height, right_v1[2]/entrance_length));

		rightTex->addValue(Vec2f(right_v2[1]/pyraEn_door_height, right_v2[2]/entrance_length));
		rightTex->addValue(Vec2f(right_v3[1]/pyraEn_door_height, right_v3[2]/entrance_length));
	}
	endEditCP (rightTex);
	
	GeoNormals3fPtr rightNorms = GeoNormals3f::create();
	beginEditCP(rightNorms, GeoNormals3f::GeoPropDataFieldMask);
	{
		for (int x = 0; x < 4; x++)
			rightNorms->addValue(Vec3f(-1,0,0));
	}
	endEditCP (rightNorms, GeoNormals3f::GeoPropDataFieldMask);
	
	// Zusammenfuegen der Eigenschaften
	GeometryPtr rightgeo=Geometry::create();
	beginEditCP (rightgeo, Geometry::TypesFieldMask    |
			Geometry::LengthsFieldMask   |
			Geometry::IndicesFieldMask   |
			Geometry::PositionsFieldMask |
			Geometry::NormalsFieldMask   |
			Geometry::MaterialFieldMask  );
	{
		rightgeo->setTypes    (rightType);
		rightgeo->setLengths  (rightLens);
		rightgeo->setIndices  (rightIndices);
		rightgeo->setTexCoords(rightTex);
		rightgeo->setPositions(rightPnts);
		rightgeo->setNormals  (rightNorms);
	}
	endEditCP (rightgeo, Geometry::TypesFieldMask    |
			Geometry::LengthsFieldMask   |
			Geometry::IndicesFieldMask   |
			Geometry::PositionsFieldMask |
			Geometry::NormalsFieldMask   |
			Geometry::MaterialFieldMask  );

	// Erstellen eines Knotens
	NodePtr rightNode = Node::create();
	beginEditCP(rightNode, Node::CoreFieldMask);
	{
		rightNode->setCore(rightgeo);
	}
	endEditCP  (rightNode, Node::CoreFieldMask);
	
	
#else
	// *********** Left ***********
	// Tuer
	// links oben
	float left_v0[3] = {0, pyraEn_door_height, entrance_length-winkel*pyraEn_door_height};
	// links unten
	float left_v1[3] = {0, 0, entrance_length};
	
	// Gang
	// links oben
	float left_v2[3] = {0, pyraEn_door_height, 0};
	// links unten
	float left_v3[3] = {0, 0, 0};
	
	// Definieren der benoetigten Typen
	GeoPTypesPtr leftType = GeoPTypesUI8::create();
	beginEditCP (leftType, GeoPTypesUI8::GeoPropDataFieldMask);
	{
		leftType->addValue(GL_QUADS);
	}
	endEditCP (leftType, GeoPTypesUI8::GeoPropDataFieldMask);
	
	// Anzahl der Punkte die fuer die einzelnen Typen benoetigt werden
	GeoPLengthsPtr leftLens = GeoPLengthsUI32::create();    
	beginEditCP (leftLens, GeoPLengthsUI32::GeoPropDataFieldMask);
	{
		leftLens->addValue(4);
	}
	endEditCP (leftLens, GeoPLengthsUI32::GeoPropDataFieldMask);
	
	// Setzen der Punkte
	GeoPositions3fPtr leftPnts = GeoPositions3f::create();
	beginEditCP (leftPnts, GeoPositions3f::GeoPropDataFieldMask);
	{		
		leftPnts->addValue(Pnt3f(left_v0[0], left_v0[1], left_v0[2]));
		leftPnts->addValue(Pnt3f(left_v1[0], left_v1[1], left_v1[2]));
		leftPnts->addValue(Pnt3f(left_v2[0], left_v2[1], left_v2[2]));
		leftPnts->addValue(Pnt3f(left_v3[0], left_v3[1], left_v3[2]));
	}
	endEditCP (leftPnts, GeoPositions3f::GeoPropDataFieldMask);

	// Zusammenfuegen der Punkte in die oben angegebenen Formen
	GeoIndicesUI32Ptr leftIndices = GeoIndicesUI32::create();
	beginEditCP (leftIndices, GeoIndicesUI32::GeoPropDataFieldMask);
	{	
		// links
		leftIndices->addValue(1);
		leftIndices->addValue(0);
		leftIndices->addValue(2);
		leftIndices->addValue(3);
	}
	endEditCP (leftIndices, GeoIndicesUI32::GeoPropDataFieldMask);

	
	GeoTexCoords2fPtr leftTex = GeoTexCoords2f::create();
	beginEditCP (leftTex);
	{
		leftTex->addValue(Vec2f(left_v0[1]/pyraEn_door_height, left_v0[2]/entrance_length));
		leftTex->addValue(Vec2f(left_v1[1]/pyraEn_door_height, left_v1[2]/entrance_length));

		leftTex->addValue(Vec2f(left_v2[1]/pyraEn_door_height, left_v2[2]/entrance_length));
		leftTex->addValue(Vec2f(left_v3[1]/pyraEn_door_height, left_v3[2]/entrance_length));
	}
	endEditCP (leftTex);
	
	GeoNormals3fPtr leftNorms = GeoNormals3f::create();
	beginEditCP(leftNorms, GeoNormals3f::GeoPropDataFieldMask);
	{
		for (int x = 0; x < 4; x++)
			leftNorms->addValue(Vec3f(1,0,0));
	}
	endEditCP (leftNorms, GeoNormals3f::GeoPropDataFieldMask);
	

	
	// Zusammenfuegen der Eigenschaften
	GeometryPtr leftgeo=Geometry::create();
	beginEditCP (leftgeo, Geometry::TypesFieldMask    |
			Geometry::LengthsFieldMask   |
			Geometry::IndicesFieldMask   |
			Geometry::PositionsFieldMask |
			Geometry::MaterialFieldMask  );
	{
		leftgeo->setTypes    (leftType);
		leftgeo->setLengths  (leftLens);
		leftgeo->setIndices  (leftIndices);
		leftgeo->setTexCoords(leftTex);
		leftgeo->setPositions(leftPnts);
		leftgeo->setNormals  (leftNorms);
	}
	endEditCP (leftgeo, Geometry::TypesFieldMask    |
			Geometry::LengthsFieldMask   |
			Geometry::IndicesFieldMask   |
			Geometry::PositionsFieldMask |
			Geometry::MaterialFieldMask  );

	// Erstellen eines Knotens
	NodePtr leftNode = Node::create();
	beginEditCP(leftNode, Node::CoreFieldMask);
	{
		leftNode->setCore(leftgeo);
	}
	endEditCP  (leftNode, Node::CoreFieldMask);
	
	
	
	// *********** Right ***********
	// Tuer
	// links oben
	float right_v0[3] = {pyraEn_door_width, pyraEn_door_height, entrance_length-winkel*pyraEn_door_height};
	// links unten
	float right_v1[3] = {pyraEn_door_width, 0, entrance_length};
	
	// Gang
	// links oben
	float right_v2[3] = {pyraEn_door_width, pyraEn_door_height, 0};
	// links unten
	float right_v3[3] = {pyraEn_door_width, 0, 0};
	
	// Definieren der benoetigten Typen
	GeoPTypesPtr rightType = GeoPTypesUI8::create();
	beginEditCP (rightType, GeoPTypesUI8::GeoPropDataFieldMask);
	{
		rightType->addValue(GL_QUADS);
	}
	endEditCP (rightType, GeoPTypesUI8::GeoPropDataFieldMask);
	
	// Anzahl der Punkte die fuer die einzelnen Typen benoetigt werden
	GeoPLengthsPtr rightLens = GeoPLengthsUI32::create();    
	beginEditCP (rightLens, GeoPLengthsUI32::GeoPropDataFieldMask);
	{
		rightLens->addValue(4);
	}
	endEditCP (rightLens, GeoPLengthsUI32::GeoPropDataFieldMask);
	
	// Setzen der Punkte
	GeoPositions3fPtr rightPnts = GeoPositions3f::create();
	beginEditCP (rightPnts, GeoPositions3f::GeoPropDataFieldMask);
	{		
		rightPnts->addValue(Pnt3f(right_v0[0], right_v0[1], right_v0[2]));
		rightPnts->addValue(Pnt3f(right_v1[0], right_v1[1], right_v1[2]));
		rightPnts->addValue(Pnt3f(right_v2[0], right_v2[1], right_v2[2]));
		rightPnts->addValue(Pnt3f(right_v3[0], right_v3[1], right_v3[2]));
	}
	endEditCP (rightPnts, GeoPositions3f::GeoPropDataFieldMask);

	// Zusammenfuegen der Punkte in die oben angegebenen Formen
	GeoIndicesUI32Ptr rightIndices = GeoIndicesUI32::create();
	beginEditCP (rightIndices, GeoIndicesUI32::GeoPropDataFieldMask);
	{	
		// links
		rightIndices->addValue(1);
		rightIndices->addValue(0);
		rightIndices->addValue(2);
		rightIndices->addValue(3);
	}
	endEditCP (rightIndices, GeoIndicesUI32::GeoPropDataFieldMask);
	
	GeoTexCoords2fPtr rightTex = GeoTexCoords2f::create();
	beginEditCP (rightTex);
	{
		rightTex->addValue(Vec2f(right_v0[1]/pyraEn_door_height, right_v0[2]/entrance_length));
		rightTex->addValue(Vec2f(right_v1[1]/pyraEn_door_height, right_v1[2]/entrance_length));

		rightTex->addValue(Vec2f(right_v2[1]/pyraEn_door_height, right_v2[2]/entrance_length));
		rightTex->addValue(Vec2f(right_v3[1]/pyraEn_door_height, right_v3[2]/entrance_length));
	}
	endEditCP (rightTex);
	
	GeoNormals3fPtr rightNorms = GeoNormals3f::create();
	beginEditCP(rightNorms, GeoNormals3f::GeoPropDataFieldMask);
	{
		for (int x = 0; x < 4; x++)
			rightNorms->addValue(Vec3f(-1,0,0));
	}
	endEditCP (rightNorms, GeoNormals3f::GeoPropDataFieldMask);
	
	// Zusammenfuegen der Eigenschaften
	GeometryPtr rightgeo=Geometry::create();
	beginEditCP (rightgeo, Geometry::TypesFieldMask    |
			Geometry::LengthsFieldMask   |
			Geometry::IndicesFieldMask   |
			Geometry::PositionsFieldMask |
			Geometry::NormalsFieldMask   |
			Geometry::MaterialFieldMask  );
	{
		rightgeo->setTypes    (rightType);
		rightgeo->setLengths  (rightLens);
		rightgeo->setIndices  (rightIndices);
		rightgeo->setTexCoords(rightTex);
		rightgeo->setPositions(rightPnts);
		rightgeo->setNormals  (rightNorms);
	}
	endEditCP (rightgeo, Geometry::TypesFieldMask    |
			Geometry::LengthsFieldMask   |
			Geometry::IndicesFieldMask   |
			Geometry::PositionsFieldMask |
			Geometry::NormalsFieldMask   |
			Geometry::MaterialFieldMask  );

	// Erstellen eines Knotens
	NodePtr rightNode = Node::create();
	beginEditCP(rightNode, Node::CoreFieldMask);
	{
		rightNode->setCore(rightgeo);
	}
	endEditCP  (rightNode, Node::CoreFieldMask);
#endif
	
	
	setName(leftNode, "entranceLeftNode");
	setName(rightNode, "entranceRightNode");
	
	
	
	// *********** Roof ***********
	NodePtr roof = makePlane(pyraEn_door_width, entrance_length-winkel*pyraEn_door_height, 50, 50);
	setName(roof, "entranceRoof");
	
	TransformPtr troof = Transform::create();
	beginEditCP(troof, Transform::MatrixFieldMask);
		m.setIdentity();
		m.setTranslate(pyraEn_door_width/2, pyraEn_door_height, entrance_length/2-winkel*pyraEn_door_height/2);
		m.setRotate(Quaternion(Vec3f(1,0,0), M_PI/2));
		troof->setMatrix(m);
	endEditCP(troof, Transform::MatrixFieldMask);
	
	NodePtr roofTrans = Node::create();
	beginEditCP(roofTrans, Node::CoreFieldMask | Node::ChildrenFieldMask);
		roofTrans->setCore(troof);
		roofTrans->addChild(roof);
	endEditCP(roofTrans, Node::CoreFieldMask | Node::ChildrenFieldMask);
	
	//Aus dem Bild eine Textur machen
	TextureChunkPtr cryptWallTex = TextureChunk::create();
	beginEditCP(cryptWallTex);
		cryptWallTex->setImage(image);
		cryptWallTex->setMinFilter(GL_LINEAR);
		cryptWallTex->setMagFilter(GL_LINEAR);
		cryptWallTex->setWrapS(GL_REPEAT);
		cryptWallTex->setWrapT(GL_REPEAT);
		cryptWallTex->setEnvMode(GL_MODULATE);
	endEditCP(cryptWallTex);
	   
	SimpleMaterialPtr cryptWallMat = SimpleMaterial::create();
	beginEditCP(cryptWallMat); 
		//Materialfarbe bei seitlicher Ansicht (Brechungswinkel)
		cryptWallMat->setAmbient(Color3f(0.3, 0.3, 0.3));    
		//Bestimmt Farbe des Materials
		cryptWallMat->setDiffuse(Color3f(1.0, 1.0, 1.0));
		cryptWallMat->setSpecular(Color3f(0.1, 0.1, 0.1));
		cryptWallMat->addChunk(cryptWallTex);
	endEditCP(cryptWallMat);
	
	GeometryPtr cryptWallGeo = GeometryPtr::dcast(roof->getCore());
	beginEditCP(cryptWallGeo);
		cryptWallGeo->setMaterial(cryptWallMat);
	endEditCP(cryptWallGeo);
	
#ifdef ENTRANCE_PLANES_ON
	cryptWallGeo = GeometryPtr::dcast(leftPass->getCore());
	beginEditCP(cryptWallGeo);
		cryptWallGeo->setMaterial(cryptWallMat);
	endEditCP(cryptWallGeo);
	
	cryptWallGeo = GeometryPtr::dcast(rightPass->getCore());
	beginEditCP(cryptWallGeo);
		cryptWallGeo->setMaterial(cryptWallMat);
	endEditCP(cryptWallGeo);
#endif
	
	cryptWallGeo = GeometryPtr::dcast(leftNode->getCore());
	beginEditCP(cryptWallGeo);
		cryptWallGeo->setMaterial(cryptWallMat);
	endEditCP(cryptWallGeo);
	
	cryptWallGeo = GeometryPtr::dcast(rightNode->getCore());
	beginEditCP(cryptWallGeo);
		cryptWallGeo->setMaterial(cryptWallMat);
	endEditCP(cryptWallGeo);
	
	
	
	// *********** Bottom ***********
	//NodePtr bottom = makeBox(pyraEn_door_width, 10, entrance_length, 10, 10, 10);
	NodePtr bottom = makePlane(pyraEn_door_width, entrance_length, 50, 50);
	setName(bottom, "entranceBottom");
	
	TransformPtr tbottom = Transform::create();
	beginEditCP(tbottom, Transform::MatrixFieldMask);
		m.setIdentity();
		m.setTranslate(pyraEn_door_width/2, 0, entrance_length/2);
		m.setRotate(Quaternion(Vec3f(1,0,0), -M_PI/2));
		tbottom->setMatrix(m);
	endEditCP(tbottom, Transform::MatrixFieldMask);
	
	NodePtr bottomTrans = Node::create();
	beginEditCP(bottomTrans, Node::CoreFieldMask | Node::ChildrenFieldMask);
		bottomTrans->setCore(tbottom);
		bottomTrans->addChild(bottom);
	endEditCP(bottomTrans, Node::CoreFieldMask | Node::ChildrenFieldMask);

	//Kammer Boden Texturen laden
	ImagePtr cryptBottomImage = Image::create();
	cryptBottomImage->read("materials/cryptBottom.jpg");
	
	//Aus dem Bild eine Textur machen
	TextureChunkPtr cryptBottomTex = TextureChunk::create();
	beginEditCP(cryptBottomTex);
		cryptBottomTex->setImage(cryptBottomImage);
		cryptBottomTex->setMinFilter(GL_LINEAR);
		cryptBottomTex->setMagFilter(GL_LINEAR);
		cryptBottomTex->setWrapS(GL_REPEAT);
		cryptBottomTex->setWrapT(GL_REPEAT);
		cryptBottomTex->setScale(0.2);
		cryptBottomTex->setEnvMode(GL_MODULATE);
	endEditCP(cryptBottomTex);
	   
	SimpleMaterialPtr cryptBottomMat = SimpleMaterial::create();
	beginEditCP(cryptBottomMat); 
		//Materialfarbe bei seitlicher Ansicht (Brechungswinkel)
		cryptBottomMat->setAmbient(Color3f(0.3, 0.3, 0.3));    
		//Bestimmt Farbe des Materials
		cryptBottomMat->setDiffuse(Color3f(1.0, 1.0, 1.0));
		cryptBottomMat->setSpecular(Color3f(0.1, 0.1, 0.1));
		cryptBottomMat->addChunk(cryptBottomTex);
	endEditCP(cryptBottomMat);

	//Mittelpunkt des Texturtraegers heraus finden und die Textur darauf legen.
	GeometryPtr cryptBottomGeo = GeometryPtr::dcast(bottom->getCore());
	beginEditCP(cryptBottomGeo);
		cryptBottomGeo->setMaterial(cryptBottomMat);
	endEditCP(cryptBottomGeo);
	
	
	
	

		
	
	// Erstellen eines Knotens
	NodePtr holeEntrance = Node::create();
	beginEditCP(holeEntrance, Node::CoreFieldMask);
	{
		holeEntrance->setCore(Group::create());
		holeEntrance->addChild(leftNode);
		holeEntrance->addChild(rightNode);
		
#ifdef ENTRANCE_PLANES_ON
		holeEntrance->addChild(leftPassTrans);
		holeEntrance->addChild(rightPassTrans);
#endif
		
		holeEntrance->addChild(roofTrans);
		holeEntrance->addChild(bottomTrans);
	}
	endEditCP (holeEntrance, Node::CoreFieldMask);
	
	
	return holeEntrance;
}
